<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

use Illuminate\Foundation\Auth\User as Authenticatable;

/*
 * when you need auth, you can extends Authenticatable
 *
 */
class ConsoleRole extends Model {

	//when you need soft-delete, you need these tow lines;
	//use SoftDeletes;
	//protected $dates = ['deleted_at'];

    protected $table = 'console_role';		//related table name
	protected $guarded = [];			//black list of fields: won't be set in batch mode; or you can use 'fillable' property

    //public $timestamps = true;							//if you've set create_at and update_at, but you dont't want to use them, you can set this 'false'

	//protected $casts = [];							//converted value

	//protected $connection = 'connection-name';		//which connection will be used
	//protected $fillable = ['name'];					//white list of fields: will be set in batch mode, The attributes that are mass assignable.
	//protected $hidden = ['password', 'remember_token'];	//the fields that should be hidden for arrays


    //---------------------------关联关系---------------------------------

    //role与apps关系
    public function apps() {
        return $this->belongsToMany(ConsoleApps::class, 'console_role_apps', 'role_id', 'apps_id');
    }


    //---------------------------scope查询-----------------------------

    //查询特定类型的所有role
    public function scopeOfSomeTypesRoles($query, $types) {
        return $query->where('types', $types);
    }



}
